"""

@uses: This script is created to so that unuceaary commas and \\n can be removed from the sql table

"""

""""Good File"""
import MySQLdb
import csv
import re

db = MySQLdb.connect(host="localhost", user="root", passwd="123",db="lsi_python")

cursor = db.cursor()
cursor2 = db.cursor()
fo = open('D:\mynew2.csv', 'wb')
spamwriter = csv.writer(fo, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL)
str = "select issue_id, title, content from duplicate_exp_data "
cursor.execute(str)
values = cursor.fetchall()
count =0
for val in values:
    count = count+1
    print "row=",count
    #print val
    
    issueid = val[0]
    title = val[1]
    desc = val[2]
    #str2 = "insert into clean_duplicate_exp_data values(%(id)d, \'%(title)s\',\'%(desc)s\')"%{'id':issueid,'title':title,'desc':desc}
    #print "or",str2
    title = title.replace(',',' ')
    title = title.replace('\'',' ')
    title = title.replace('\"',' ')
    title = title.replace('\n',' ')
    title = title.replace('\r',' ')
    title = title.replace('\t',' ')
    title = title.replace('\\',' ')
    desc= desc.replace(',',' ')
    desc = desc.replace('\r\n',' ')
    desc = desc.replace('\n',' ')
    desc = desc.replace('\r',' ')
    desc = desc.replace('\t',' ')
    desc = desc.replace('\'',' ')
    desc = desc.replace('\"',' ')
    desc = desc.replace('\\',' ')
    #desc = desc.replace('\\r\\n',' ')
    #desc = re.sub('\s+',' ',desc)
 
   
    title = title.strip()
    desc = desc.strip()
    spamwriter.writerow([issueid,title,desc])
    str2 = "insert into clean_duplicate_exp_data values(%(id)d, \'%(title)s\',\'%(desc)s\')"%{'id':issueid,'title':title,'desc':desc}
    #print "val",val
    cursor2.execute(str2)
fo.close()   
db.commit()    